<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { auditApi } from '@/api/controller';
  import { getPlayEndTime, getDateArray } from '@/utils'
  import { ToastSuccess, ToastWarning, Toastloading } from '@/utils/public';
  import Pagination from "@/components/Pagination/index.vue";
  import xmDatePicker from '@/components/xmDatePicker/index.vue';
  import { ElMessageBox } from 'element-plus';
  const action = reactive({
    total:0,
    setStatus:0,
    list:[] as any[],
    adminList:[] as any[],
    timeObj:getPlayEndTime(getDateArray('ymdhis'))
  })
  const initialQuery = {
    uuid:'',
    type: 11,
    time_out: 0,
    status: 1,
    opt_id: "",
    check_status: 0,
    second_status: 0,
    page: 1,
    limit: 10,
  }
  const listQuery = reactive({...initialQuery})
  /**
   * 审核
   * a_type: 2复审
   * u_status: 1审核通过 2审核驳回
   * u_type: 1单个审核 2当前页全部审核
   */
   const handlePass = (row:any = {},u_status=0,u_type=0)=>{
    if(!u_type) return ToastWarning('u_type 不存在')
    if(!u_status) return ToastWarning('u_status 不存在')
    const { id=0 } = row
    if(u_type == 1) {
      if(!id) return ToastWarning('id 不存在')
    }
    const title = u_type == 1?`确定复审${['','已阅','驳回'][u_status]}此文字内容吗?`:"确定复审通过当前页所有文字内容吗"
    ElMessageBox.confirm(title, "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
    .then(async () => {
      const loading = Toastloading()
      const { page, limit, type, check_status } = listQuery
      let query = {
        type,
        content_id:'',
        a_type:2,
        u_type,
        u_status,
        check_status
      } as any
      if(u_type == 1) {
        query.content_id = id
      }
      if(u_type == 2) {
        query.content_id = id
        query['page'] = page
        query['limit'] = limit
      }
      await auditApi.setAuditStatus(query)
      getList()
      ToastSuccess('操作成功')
      loading.close()
    })
    .catch(() => {});
  }
  const resetQuery = ()=>{
    action.timeObj = getPlayEndTime(getDateArray('ymdhis'))
    Object.assign(listQuery,{
      ...initialQuery
    })
    getList()
  }
  const handleSerach = ()=>{
    listQuery.page = 1
    getList()
  }
  const getAdmins = async()=>{
    const res = await auditApi.getAdmins()
    const { data=[] } = res
    action.adminList = data
  }
  const getList = async()=> {
    const loading = Toastloading()
    const { playTime:begin_date, endTime:end_date } = action.timeObj
    const res = await auditApi.checkSecondContent({
      begin_date,
      end_date,
      ...listQuery
    })
    loading.close()
    const { data=[], total=0 } = res.data
    action.list = data
    action.total = total
    action.setStatus = listQuery.status
  }
  onMounted(()=>{
    getAdmins()
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">用户UUID：</div>
          <el-input v-model="listQuery.uuid"  placeholder="用户UUID" />
        </div>
        <div class="labelItem">
          <div class="label">处理类型：</div>
          <el-select  v-model="listQuery.type" placeholder="请选择处理类型" >
            <el-option label="查看评论" :value="11"/>
            <el-option label="评论回复" :value="12"/>
          </el-select>
        </div>
        <div class="labelItem">
          <div class="label">审核进度：</div>
          <el-select  v-model="listQuery.status" placeholder="请选择审核进度" >
            <el-option label="查看初审" :value="1" />
            <el-option label="查看复审" :value="2" />
          </el-select>
        </div>
        <div class="labelItem">
          <div class="label">初审状态：</div>
          <el-select  v-model="listQuery.check_status" placeholder="请选择初审状态" >
            <el-option label="初审全部" :value="0" />
            <el-option label="初审通过" :value="1" />
            <el-option label="初审驳回" :value="2" />
          </el-select>
        </div>
        <div class="labelItem">
          <div class="label">复审状态：</div>
          <el-select v-model="listQuery.second_status" placeholder="请选择复审状态" >
            <el-option label="复审全部" :value="0" />
            <el-option label="复审通过" :value="1" />
            <el-option label="复审驳回" :value="2" />
          </el-select>
        </div>
        <div class="labelItem">
          <div class="label">审核人：</div>
          <el-select v-model="listQuery.opt_id" placeholder="请选择审核人" >
            <el-option
              v-for="(option, key) of action.adminList"
              :label="option.name"
              :value="option.id"
            />
          </el-select>
        </div>
        <div class="labelItem">
          <div class="label">超时筛选：</div>
          <el-select v-model="listQuery.time_out" placeholder="请选择超时类型" >
            <el-option label="全部" :value="0" />
            <el-option label="3分钟" :value="3" />
            <el-option label="5分钟" :value="5" />
            <el-option label="10分钟" :value="10" />
            <el-option label="30分钟" :value="30" />
            <el-option label="60分钟" :value="60" />
          </el-select>
        </div>
        <xmDatePicker v-model:timeval="action.timeObj" />
      </div>
      <div class="labelBox">
        <el-button type="primary" @click="handleSerach">查询</el-button>
        <el-button type="primary" @click="resetQuery">重置</el-button>
        <el-button v-if="action.setStatus == 1" type="success" @click="handlePass({},1,2)">一键通过</el-button>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column width="100" prop="uuid" label="用户UUID" />
      <el-table-column min-width="160" prop="text_content" label="内容" />
      <el-table-column width="95" label="审核类型">
        <template #default="scoped">
          <el-tag>{{ ["待审核", "初审完毕", "复审完毕"][scoped.row.status] }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column width="120" label="初审人员">
        <template #default="scoped">
          <el-tag>{{ scoped.row.first_opt_name }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column width="95" label="初审状态">
        <template #default="scoped">
          <el-tag
            :type="['','success','danger',''][scoped.row.check_status]"
          >
          {{ ["未审核", "通过", "驳回"][scoped.row.check_status] }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column width="110" prop="first_date" label="初审时间" />
      <el-table-column width="95" prop="diff_time" label="审核用时" />
      <el-table-column width="120" label="复审人员">
        <template #default="scoped">
          <el-tag>{{ scoped.row.second_opt_name }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column width="90" label="复审状态">
        <template #default="scoped">
          <el-tag
            :type="['','success','danger',''][scoped.row.review_check_status]"
          >
          {{ ["未审核", "通过", "驳回"][scoped.row.review_check_status] }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column width="110" prop="second_date" label="复审时间" />
      <el-table-column width="110" prop="created_at" label="提交时间" />
      <el-table-column v-if="action.setStatus == 1" fixed="right" width="180" label="操作">
        <template #default="scoped">
          <el-button type="success" @click="handlePass(scoped.row,1,1)">已阅</el-button>
          <el-button type="danger" @click="handlePass(scoped.row,2,1)">驳回</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
  </div>
</template>